<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/15
 * Time: 11:43
 */

namespace app\domain;


use app\controller\commonController;
use app\server\carData;
use app\server\request;
use rap\config\Config;

class car
{
    public function addUserDrivingInfo ($data, $car_name, $car_set,$car_model,$phone,$id_card, $name, $driving_img, $jiazhao_img, $jiazhao_img2, $user_id, $head) {
        //解析获取数据
        $driving_obj = (array)json_decode($data[1]);
        $driving_data = (array)$driving_obj['Data'];
        //行驶证信息
        $data_dr = [
            'car_code' => $driving_data['plate_num'],
            'car_type' => $driving_data['vehicle_type'],
            'car_owner' => $driving_data['owner'],
            'address' => $driving_data['address'],
            'use_type' => $driving_data['useCharacter'],
            'model_type' => $driving_data['model'],
            'class_code' => $driving_data['vin'],
            'engine_code' => $driving_data['engine_num'],
            'register_time' => $driving_data['register_date'],
            'user_id' => $user_id,
            'user_head' => $head,
            'car_name' => $car_name,
            'car_set' => $car_set,
            'car_model' => $car_model,
            'phone' => $phone,
            'id_card' => $id_card,
            'jiazhao_img' => $jiazhao_img,
//            'jiazhao_img2' => $jiazhao_img2,
            'driving_img' => $driving_img,
            'name' => $name,
            'status' => 1,
            'create_time' => commonController::getDateTime()
        ];

        $res = carData::addCarAuthInfo($data_dr);

        return $res;
    }


    public function addUserJzInfo($user_id, $data) {
        //数据解析
        $jiazhao_obj = (array)json_decode($data[1]);
        $jiazhao_data = (array)$jiazhao_obj['Data'];
        //驾照信息
        $gender = 1;
        if ($jiazhao_data['gender'] == '女') $gender = 0;
        $data_jz = [
            'user_id' => $user_id,
            'id_number' => $jiazhao_data['idNumber'],
            'name' => $jiazhao_data['name'],
            'gender' => $gender,
            'nation' => $jiazhao_data['nation'],
            'address' => $jiazhao_data['address'],
            'birthday' => $jiazhao_data['birthday'],
            'start_time' => $jiazhao_data['validFrom'],
            'end_time' => $jiazhao_data['validFor'],
            'type' => $jiazhao_data['cls'],
            'create_time' => commonController::getDateTime(),
        ];

        $res = carData::addUserJZInfo($data_jz);

        return $res;
    }


    public function getUserCarInfo ($where, $field) {
        //获取用户单条汽车数据
        $data = carData::getUserCarInfoData($where, $field);

        return $data;
    }

    /**
     * 获取用户所有汽车信息
     * @param $where
     * @param $field
     * @param int $page
     * @param int $limit
     * @return array
     */
    public function getUserCarInfos($where, $field) {
        //获取用户汽车数据
        $data = carData::getUserCarInfoDatas($where, $field, $page = 1, $limit = 10);
        return $data;
    }

    public function addCarCityInfos($data) {
        //获取用户汽车数据
        $res = carData::insertCarCityInfo($data);

        return $res;
    }

    public function getUserDriInfo ($where, $field) {

        $data = carData::getUserJzInfo($where, $field);

        return $data;
    }

    public function deleteUserCarInfo ($where) {

        $data = [
            'is_del' => 1
        ];
        $res = carData::deleteUserCarInfo($where, $data);

        return $res;
    }

    public function getOilPrice ($provice_name) {

        $config = Config::getFileConfig();
        $oil_url = $config['oil_url']['url'];

        $data = request::getMethod($oil_url);
        //获取数据
        $data = $data['result'];
        if($data) {
            //循环遍历获取山东省数据
            for ($i = 0; $i < count($data); $i++) {
                if ($data[$i]['city'] = $provice_name) {
                    $res = $data[$i];
                    break;
                }
            }
        } else {
            $res = [];
        }
        return $res;
    }

    public function getCarNameList ($where, $field) {

        $res = carData::getCarNameData($where, $field);

        return $res;
    }

    public function getCarSetInfoList ($where, $field) {

        $data = carData::getCarSetData($where, $field);

        return $data;
    }

    public function getCarModelInfoList ($where, $field) {

        $data = carData::getCarModelData($where, $field);

        return $data;
    }

    public function getRequestResult($url, $param) {

        $data = request::getMethod($url, $param);


        return $data;
    }
}